package com.kotlin.demo

import androidx.lifecycle.ViewModel
import com.kotlin.demo.net.ApiResponse

/**
 *    author : fang.zhang
 *    e-mail : initzf@126.com
 *    date   : 2019-12-24
 *    desc   :
 */
suspend fun <T> ViewModel.call(job: suspend () -> T): ApiResponse<T> {
    return try {
        ApiResponse(job())
    } catch (e: java.lang.Exception) {
        ApiResponse(e)
    }
}
